package com.wyw.design.model.learning.behavioral.iteratorpattern;

import java.util.ArrayList;
import java.util.Vector;

/**
 * @Title   迭代器演示示例
 * @Description
 * @Author Mr Wu yewen.wu.china@gmail.com
 * @Date 2023/4/18 10:24
 * Update History:
 * Author        Time            Content
 */
public class IteratorUseDemo {
    void doIterator() {
        // 定义 Vector 集合
        Vector vector = new Vector();
        vector.add("Vector 1");
        vector.add("Vector 2");
        vector.add("Vector 3");
        // 定义 ArrayList 集合
        ArrayList list = new ArrayList();
        list.add("ArrayList 1");
        list.add("ArrayList 2");
        list.add("ArrayList 3");
        // 使用迭代器循环 Vector
        java.util.Iterator vIterator = vector.iterator();
        while (vIterator.hasNext()) {
            System.out.println(vIterator.next());
        }
        // 使用迭代器循环 ArrayList
        java.util.Iterator lIterator = list.iterator();
        while (lIterator.hasNext()) {
            System.out.println(lIterator.next());
        }
    }

}